package com.rongke.web.heepay;


import com.rongke.web.heepay.config.PartnerConfig;
import com.rongke.web.heepay.util.HttpUtil;
import com.rongke.web.heepay.util.SmallTools;

/**
 * Created by Administrator on 2018/2/8.
 * 支付确认
 *
 * 快捷API支付流程
 * 1.调用签约查询接口获取签约的授权码及卡信息
 * 2.调用快捷支付请求接口获取token（有授权码可传入授权码，无授权码传空字符串并填写银行卡信息）
 * 3.调用快捷支付确认接口，传入短信验证码和token等信息完成支付
 */
public class PayConfirm {
    /*public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        System.out.println(a);
        getToken();
    }*/

    public static String getToken(String verifyCode,String requestUserIp,String creditCardInfo,String token) {
        String url = "https://open.heepay.com/quickPayConfirm.do";

        //请求参数
        //*注：此demo中的参数仅供测试使用，切勿上线使用，上线产品请使用自己的账号
        String merchantId = PartnerConfig.merchantId;//商户号
        //短信验证码
        //String creditCardInfo = "";//信用卡信息

       // String token = "137a379b63814f628a890a1263091df8";//支付令牌
        String version = PartnerConfig.version;//版本
        String sign = "";//签名
        String key = PartnerConfig.payKey;//商户密钥
        String deskey = key.substring(0,24);//商户密钥

        //3DES加密姓名和身份证号
        //creditCardInfo = Des.Encrypt3Des(creditCardInfo,deskey);
        //拼接签名串
        String sign1 = "creditCardInfo="+creditCardInfo+
                "&merchantId="+merchantId+
                "&requestUserIp="+requestUserIp+
                "&token="+token+
                "&verifyCode="+verifyCode+
                "&version="+version+
                "&key="+key;

        System.out.println("签名参数："+sign1);
        //对签名参数进行MD5加密得到sign
        sign = SmallTools.MD5en(sign1);
        //拼接请求参数
        String parameter = "merchantId="+merchantId+
                "&verifyCode="+verifyCode+
                "&creditCardInfo="+creditCardInfo+
                "&requestUserIp="+requestUserIp+
                "&token="+token+
                "&version="+version+
                "&version="+version+
                "&sign="+sign;
        System.out.println("请求参数："+parameter);
        String ret = HttpUtil.sendPost(url,parameter);
        System.out.println("返回的数据："+ret);
        Boolean isSign = SmallTools.checkSign(ret, key);
        System.out.println("验签结果："+isSign);
        if (isSign){
            return ret;
        }else {
            return "{\"retMsg\":\"返回数据验签失败\"}";
        }
    }
}
